﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Collections;

public partial class WebSite_QuestionControlEdit : System.Web.UI.UserControl
{
    public int Count;
    public string Title;
    public Dictionary<string, string> Content;
    public WebSite_QuestionControlEdit()
    {
        Count = 4;
        Title = "";
        Content = new Dictionary<string, string>();
    }
    public WebSite_QuestionControlEdit(int count,string title,Dictionary<string, string> content)
    {
        Count = count;
        Title = title;
        Content = content;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int i;
        for (i = 1; i <= Count;i++ )
        {
            AddItem(i);
        }
        i=1;
        TitleTextBox.Text = Title;
        foreach (KeyValuePair<string,string>element in Content)
        {
            ((TextBox)this.FindControl("ItemTextBox" + i.ToString())).Text = element.Key ;
            i++;
        }
    }
    //增加选项
    private void AddItem(int num)
    {
        TableRow row = new TableRow();
        TableCell cellHead = new TableCell();
        TableCell cellContent = new TableCell();
        Label LabelAuditing = new Label();
        TextBox TextAuditing = new TextBox();
        LabelAuditing.ID = "ItemNameLabel" + num.ToString();
        LabelAuditing.Text = "选项" + (num).ToString()+":";
        TextAuditing.ID = "ItemTextBox" + num.ToString();
        TextAuditing.Height = 18;

        cellHead.Controls.Add(LabelAuditing);
        cellContent.Controls.Add(TextAuditing);
        cellHead.BackColor = System.Drawing.Color.FromName("#EFEFEF");
        cellHead.HorizontalAlign = HorizontalAlign.Right;
        cellHead.Width = 100;
        cellContent.BackColor = System.Drawing.Color.FromName("#EFEFEF");
        cellContent.HorizontalAlign = HorizontalAlign.Left;
        cellContent.Width = 400;
        row.Cells.Add(cellHead);
        row.Cells.Add(cellContent);
    }
    //获得所有选项的内容
    public Dictionary<string,string> GetContent()
    {
        Content["Title"] = TitleTextBox.Text;
        for (int i=1;i<=Count;i++)
        {
             Content["Item"+i.ToString()]=((TextBox)this.FindControl("ItemTextBox"+i.ToString())).Text;
        }  
    }
    protected void AddItemBtn_Click(object sender, EventArgs e)
    {
        Count++;
        AddItem(Count);
    }
}
